package com.duleme.servlet;

import com.duleme.common.EncodeUtils;
import com.duleme.common.JsonUtils;
import com.duleme.dao.DeliveryDao;
import com.duleme.entity.Delivery;
import com.duleme.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "AddressServlet",urlPatterns = "/show/address")
public class AddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EncodeUtils.setEncoding(request,response);
        User user = (User) request.getSession().getAttribute("user");
        /*User user = new User();
        user.setUserId(100020);*/
        int userID = user.getUserId();
        List<Delivery> list = new DeliveryDao().getDeliveryByUserID(userID);
        String json = JsonUtils.object2Json(list);
        response.getWriter().write(json);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
